package com.wms.controller;

import com.wms.common.CallBack;
import com.wms.common.Response;
import com.wms.domain.LoginDomain;
import com.wms.domain.RoleDomain;
import com.wms.service.Employees.EmployeesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Api(tags = "职员信息")
@RequestMapping(path = "/Login/")
@RestController
public class Login {
    @Autowired
    private EmployeesService employeesService;
    @ApiOperation(value = "查询员工信息")
    @RequestMapping(path = "getLoginPage", method = RequestMethod.POST)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "billNo", value = "结算单号(32)", required = true) })
//    public Response getLoginList(final String billNo) {
    public Response getLoginPage(@RequestBody LoginDomain login) {
        return new CallBack() {
            @Override
            protected Object run() {
                return employeesService.getLoginPage(login);
            }
        }.execute();
    }

    @ApiOperation(value="增加员工信息")
    @RequestMapping(path="addLogin",method=RequestMethod.POST)
    public Response addLogin(@RequestBody LoginDomain login){
        return new CallBack() {
            @Override
            protected Object run() {
                return employeesService.add(login);
            }
        }.execute();

    }

    @ApiOperation(value="切换状态")
    @RequestMapping(path="changeEmpStat",method=RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true),
            @ApiImplicitParam(name = "emp_stat", value = "emp_stat", required = true)})
    public Response changeEmpStat(final Long id, Long emp_stat){
        return new CallBack() {
            @Override
            protected Object run() {
                return employeesService.changeEmpStat(id,emp_stat);
            }
        }.execute();

    }

    @ApiOperation(value="删除用户")
    @RequestMapping(path="deleteEmp",method=RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true)})
    public Response deleteEmp(final Long id){
        return new CallBack() {
            @Override
            protected Object run() {
                return employeesService.deleteEmp(id);
            }
        }.execute();

    }
    @ApiOperation(value="登录")
    @RequestMapping(path="login",method=RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户名", required = true),
            @ApiImplicitParam(name = "password", value = "密码", required = true)})
    public Response login(HttpServletRequest request,HttpServletResponse response, final String id, final String password){
        return new CallBack() {
            @Override
            protected Object run() {
                return employeesService.login(request,response,id,password);
            }
        }.execute();

    }




    //Role

    @ApiOperation(value = "查询角色信息")
    @RequestMapping(path = "getRolePage", method = RequestMethod.POST)
    public Response getRolePage(@RequestBody RoleDomain roleDomain) {
        return new CallBack() {
            @Override
            protected Object run() {
                return employeesService.getRolePage(roleDomain);
            }
        }.execute();
    }

    @ApiOperation(value="增加角色信息")
    @RequestMapping(path="addRole",method=RequestMethod.POST)
    public Response addRole(@RequestBody RoleDomain roleDomain){
        return new CallBack() {
            @Override
            protected Object run() {
                return employeesService.addRole(roleDomain);
            }
        }.execute();

    }


    @ApiOperation(value="删除角色")
    @RequestMapping(path="deleteRole",method=RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true)})
    public Response deleteRole(final Long id){
        return new CallBack() {
            @Override
            protected Object run() {
                return employeesService.deleteRole(id);
            }
        }.execute();
    }
}
